

-- Namespace
	local _,mod = ...


-- Object reference
	local units = mod.units
	local resolve = mod.resolve


-- Dispel table
	-- To do: spell/talent tracking to build this list in real time.
	local dispel = {}
	
	local _,class = UnitClass('player')
	if class == 'DRUID' then
		dispel['Curse'] = 1
		dispel['Poison'] = 4
	elseif class == 'MAGE' then
		dispel['Curse'] = 1
	elseif class == 'PALADIN' then
		dispel['Disease'] = 2
		dispel['Magic'] = 3
		dispel['Poison'] = 4
	elseif class == 'PRIEST' then
		dispel['Disease'] = 2
		dispel['Magic'] = 3
		dispel['Poison'] = 4
	elseif class == 'SHAMAN' then
		dispel['Curse'] = 1
		dispel['Magic'] = 3
	elseif class == 'WARLOCK' then
		dispel['Magic'] = 3
	else
		dispel = nil
	end


-- Events
	if dispel then
		local care = mod:unitevent_care('dispel')
		if care then
			local has = {}
			
			local function DISPEL(unit)
				if not care[unit] then return end
				local u = units[unit]
				
				if UnitIsFriend('player',unit) and UnitPlayerControlled(unit) then
					wipe(has)
					local valid,dtype,_,slot
					for i = 1,40 do
						valid,_,_,_,dtype = UnitAura(unit,i,'HARMFUL')
						if valid then
							slot = dispel[dtype]
							if slot then
								has[slot] = true
							end
						else
							break
						end
					end
					u:Update('dispel',unpack(has,1,4))
				else
					u:Update('dispel',nil)
				end
			end
			
			mod:event_register('UNIT_AURA',DISPEL)
			
			resolve[#resolve+1] = DISPEL
		end
	end
